import Vue from 'vue'
import App from '@/App'
import store from '@/store'

Vue.config.productionTip = false
App.mpType = 'app'

// 引入全局uView
import uView from '@/uni_modules/uview-ui'
Vue.use(uView)

// 注册全局过滤器
import * as filters from '@/utils/filters'
for (const key in filters) {
  Vue.filter(key, filters[key])
}

Vue.prototype.toParams = function (param) {
    var result = ""
    for (let name in param) {
        if (typeof param[name] != 'function') {
            result += "&" + name + "=" + encodeURI(param[name]);
        }
    }
    return result.substring(1)
}


/**
 * 字符权限校验
 * @param {Array} value 校验值
 * @returns {Boolean}
 */
Vue.prototype.checkPermi = function (value) {
  if (value && value instanceof Array && value.length > 0) {
    const permissions = store.state.initData.initData.permissions
    const permissionDatas = value
    const all_permission = "*:*:*";

    const hasPermission = permissions.some(permission => {
      return all_permission === permission || permissionDatas.includes(permission)
    })

    if (!hasPermission) {
      return false
    }
    return true
  } else {
    return false
  }
}

const app = new Vue({
  ...App,
  store,
})

// 引入请求封装，将app参数传递到配置中
require('@/utils/request')(app)
app.$mount()

